<?php
include '../Module/GalleryModule.php';
$Module=new GalleryModule();
if(isset($_REQUEST["action"])){
    switch ($_REQUEST["action"]){
        case "add":
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            if($Module->insert($name)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "edit":
            $id                 =isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            if($Module->update($id,$name)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
            break;
        case "delete":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($Module->delete($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "restore":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($Module->restore($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "addimg":
            $album		=isset($_REQUEST["album"])?EndcodeStr($_REQUEST["album"]):"";
            $img		=isset($_REQUEST["img"])?EndcodeStr($_REQUEST["img"]):"";
            if($Module->insertimg($album, $img)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "editimg":
            $id                 =isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            $img		=isset($_REQUEST["img"])?EndcodeStr($_REQUEST["img"]):"";
            if($Module->updateimg($id,$img)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
            break;
        case "deleteimg":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($Module->deleteimg($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "restoreimg":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($Module->restoreimg($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
    }    
}
?>
